package mypaint;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyPaint extends JFrame {

    Image ball = PaintUtil.getImage("images/ball.png");

    public void paint(Graphics g){  //自动被调用，g相当于一支画笔
        Color c = g.getColor();
        Font f = g.getFont();

        g.setColor(Color.BLUE);
        g.drawLine(100,100,300,300);
        g.drawRect(100,100,300,300);
        g.drawOval(100,100,300,300);

        g.setColor(Color.red);
        g.setFont(new Font("宋体",Font.BOLD,50));
        g.drawString("我是谁？",200,200);

        g.drawImage(ball,250,250,null);

        g.setColor(c);
        g.setFont(f);

    }


    public void lanchFrame(){

        setTitle("CTY作品");  //在游戏窗口打印标题
        setVisible(true);  //窗口默认不可见，设为可见
        setSize(500,500);  //窗口大小
        setLocation(300,300);  //窗口左上角定点的坐标位置

        //增加关闭窗口监听，这样用户点击窗口右上角关闭图标，可以关闭游戏程序
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

    }

    public static void main(String[] args){
        MyPaint f = new MyPaint();
        f.lanchFrame();
    }

}
